import * as cc from "cc";
import { GameMainEvent } from "../../../const/GameEvents";
import VCFlyIcon from "../vc/VCFlyIcon";
import { ViewLayer } from './../../../../framework/view/ViewConsts';
import ViewModelBase from "./../../../../framework/view/ViewModelBase";

/**飞图标组件传入数据 */
export interface FlyIconData {
    /**飞图标终点位置 */
    targetWorldPos: cc.Vec3,
    /**飞行的原始节点 */
    iconNode?: cc.Node,
    /**飞行图标图片名 优先iconNode */
    iconName?: string,
    /**
     * 如果配置iconName飞行图标的路径名 基于resources目录下开始 最后不包含/
     * 不传走默认路径 game/prefab/mvc/fly_icon/texture
     */
    iconPath?: string,
    /**飞图标起始位置,如果不传,默认飞行图标起始位置 */
    fromWorldPos?: cc.Vec3,
    /**需要创建的数量 */
    flyCount?: number,
    /**飞行图标的初始点缩放比例 */
    iconScaleFrom?: number,
    /**飞行图标的终点缩放比例 */
    iconScaleTo?: number,
    /**初始随机位置范围半径 */
    randomRadius?: number,
    /**飞行图标的根节点,用于设置层级 */
    iconRoot?: cc.Node,
    /**飞行图标的根节点层级 优先iconRoot*/
    iconRootLayer?: ViewLayer,
}

export default class ModelFlyIcon extends ViewModelBase {
    static modelName: string = "ModelFlyIcon";

    public static flyIcon(data: FlyIconData, callback?: () => void) {
        const model = ModelFlyIcon.getInstance() as ModelFlyIcon;
        model.flyIcon(data, callback);
    }

    initData(data: any) {

    }

    tryEnter(params?: { [key: string]: any, hideOther?: boolean, unHideNames?: string[] }) {
        if (!this.checkEnable()) {
            return;
        }
        this.showView(VCFlyIcon, params)
    }

    checkEnable() {
        return true;
    }

    flyIcon(data: FlyIconData, callback?: () => void) {
        GameMainEvent.ON_FLY_ICON.emit(data, callback);
    }
}
